package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/4 19:57
 * @description
 */
public class Code429 {
    private List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> levelOrder(Node root) {
        setResult(root, 0);
        return result;
    }

    private void setResult(Node node, int deep) {
        if (node == null) { return; }
        if (result.size() <= deep) {
            result.add(new ArrayList<>());
        }
        result.get(deep).add(node.val);
        deep++;
        if (node.children != null) {
            for (Node child : node.children) {
                setResult(child, deep);
            }
        }
    }
}
